Page({
  data: {
    bankName: '',
    bankIcon: '',
    cardNumber: '',
    cardHolder: '',
    idNumber: '',
    phoneNumber: ''
  },

  onLoad(query) {
    this.setData({
      bankName: query.bankName || '',
      bankIcon: query.bankIcon || ''
    });
  },

  handleInputChange(e) {
    const { field } = e.currentTarget.dataset;
    this.setData({
      [field]: e.detail.value
    });
  },

  handleSubmit() {
    const { bankName, cardNumber, cardHolder, idNumber, phoneNumber } = this.data;
    
    if (!cardNumber || !cardHolder || !idNumber || !phoneNumber) {
      my.showToast({
        content: '请填写完整信息',
        icon: 'none'
      });
      return;
    }

    my.showLoading({
      content: '正在提交...'
    });

    // 模拟API请求
    setTimeout(() => {
      my.hideLoading();
      my.showToast({
        content: `${bankName}银行卡添加成功(模拟)`,
        success: () => {
          // 返回上一页并传递模拟数据
          const pages = getCurrentPages();
          const prevPage = pages[pages.length - 2];
          prevPage.setData({
            simulatedCard: {
              bankName,
              cardNumber,
              cardHolder,
              idNumber,
              phoneNumber
            }
          });
          my.navigateBack();
        }
      });
    }, 2000);
  }
});